<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="4">
        <el-tree ref="orgTree" :data="treeData" node-key="id" :expand-on-click-node="false" default-expand-all  highlight-current @node-click="treeClick"></el-tree>
      </el-col>
      <el-col :span="20">
        <div>
          <el-form ref="searchForm" label-width="100px">
            <el-row :gutter="20">
              <el-col :span="14">
                <el-form-item label="礼品名称">
                  <el-input v-model="sd.searchName" size="small" placeholder="礼品名称"/>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-button class="mt_5" type="primary" size="mini" icon="el-icon-search" @click="searchGift">查询</el-button>
              </el-col>
            </el-row>
          </el-form>
          <el-table :data="giftObj.list" border style="width: 100%" @row-dblclick="selectGift">
            <el-table-column label="礼品名称" prop="name"></el-table-column>
            <el-table-column label="礼品分类" prop="typename"></el-table-column>
            <el-table-column label="礼品规格" prop="guige"></el-table-column>
            <el-table-column label="礼品品牌" prop="pinpai"></el-table-column>
          </el-table>
          <el-alert title="双击礼品行选择" type="warning" :closable="false"></el-alert>
          <el-pagination v-if="giftObj.total>sd.pageSize" class="center" background layout="total, prev, pager, next"
                         @current-change="loadGift" :total="giftObj.total"
                         :current-page.sync="sd.pageNum" :page-size="sd.pageSize">
          </el-pagination>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import request from "@/utils/request";
import FileEntityType from "../../utils/FileEntityType";
export default {
  data() {
    return {
      FileEntityType : FileEntityType,
      treeData : [],

      sd: {
        typeId: 0,
        searchName:"",
        pageNum: 1,
        pageSize: 10
      },
      giftObj:{},
    }
  },
  mounted() {
    this.loadGiftTypeTree();
    this.loadGift();
  },
  methods: {
    loadGiftTypeTree(){
      request({
        url: '/gift/gifttype/gettreenode',
        data: {}
      }).then(res => {
        const { data } = res
        this.treeData = data
      })
    },
    treeClick(treeNode){
      this.sd.typeId = parseInt(treeNode.id)
      this.sd.pageNum=1
      this.sd.pageSize=10
      this.sd.searchName=''
      this.loadGift();
    },
    searchGift(){
      this.sd.pageNum = 1;
      this.loadGift();
    },
    loadGift() {
      request({
        url: '/gift/gift/listgift',
        data: this.sd
      }).then(res => {
        const { data } = res
        this.giftObj = data
      })
    },
    selectGift(row,column,event){
      this.$emit("selected", row)
      this.$emit('update:visible', false);  //关闭弹窗
    }
  },
}
</script>

<style scoped>

</style>
